package br.com.lis;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.OnInitializedListener;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayerFragment;

import android.os.Bundle;

public class VideoFragment  extends YouTubePlayerFragment{
	 public VideoFragment() { }
	    public static VideoFragment newInstance(String url) {
	        VideoFragment f = new VideoFragment();
	        Bundle b = new Bundle();
	        b.putString("url", url);
	        f.setArguments(b);
	        f.init();
	        return f;
	    }
	    private void init() {
	        initialize("AIzaSyCDl7U4RxdTlCWxoH4zCT73M_1orzEIUio", new OnInitializedListener() {
	            @Override
	            public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) { }
	            @Override
	            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player, boolean wasRestored) {
	                if (!wasRestored) { 
	                    player.cueVideo(getArguments().getString("url"));
	                }
	            }
	        });
	    }	
}
